//
//  SpotsTableViewCell.m
//  littleLight's Project-A
//
//  Created by dllo on 16/5/26.
//  Copyright © 2016年 light. All rights reserved.
//

#import "SpotsTableViewCell.h"
#import "SpotsCollectionViewCell.h"
#import "SpotsModel.h"
@interface SpotsTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation SpotsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
        
    }
    return self;
    
}



- (void)createCollectionView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width / 4 * 3, 350);
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    flowLayout.minimumInteritemSpacing = 5;
    flowLayout.minimumLineSpacing = 5;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.conllectionV = [[UICollectionView alloc] initWithFrame:self.contentView.frame collectionViewLayout:flowLayout];
    self.conllectionV.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.conllectionV];
    self.conllectionV.delegate = self;
    self.conllectionV.dataSource = self;
    [self.conllectionV registerClass:[SpotsCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.conllectionV.frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width , 360);
    
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.array.count;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SpotsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    SpotsModel *model = [self.array objectAtIndex:indexPath.row];
    cell.model = model;
    cell.backgroundColor = [UIColor colorWithRed:251 / 255.0  green:248 / 255.0 blue:241 / 255.0 alpha:1];
    return cell;
    
}






@end
